import logging


def init_logging(name):
    # logger = logging.root
    # use 'airtest' as root logger name to prevent changing other modules' logger
    logging.basicConfig(
        level=logging.INFO,
        filename='../logs/test.log',
        filemode='w',
        format='[%(asctime)s][%(levelname)s]<%(name)s> %(message)s',
        datefmt='%I:%M:%S'
    );

    logger = logging.getLogger(name)
    handler = logging.FileHandler('../logs/test.log')
    handler.setLevel(logging.INFO)
    console = logging.StreamHandler()
    console.setLevel(logging.INFO)
    formatter = logging.Formatter(
        fmt='[%(asctime)s][%(levelname)s]<%(name)s> %(message)s',
        datefmt='%I:%M:%S'
    )
    handler.setFormatter(formatter)

    logger.addHandler(handler)
    logger.addHandler(console)


def get_logger(name):
    init_logging(name)
    logger = logging.getLogger(name)
    return logger
